﻿namespace _6.原型模式;

public class Resume : ICloneable
{
    private string? name;
    private string? sex;
    private string? age;
    private WorkExperience work;

    public Resume(string name)
    {
        this.name = name;
        work = new WorkExperience();
    }

    private Resume(WorkExperience work)
    {
        //提供Clone方法调用的私有构造函数，以便克隆“工作经历”的数据
        this.work = (WorkExperience)work.Clone();
    }

    /// <summary>
    /// 设置个人信息
    /// </summary>
    /// <param name="sex">性别</param>
    /// <param name="age">年龄</param>
    public void SetPersonalInfo(string sex, string age)
    {
        this.sex = sex;
        this.age = age;
    }

    /// <summary>
    /// 设置工作经历
    /// </summary>
    /// <param name="workDate">工作日期</param>
    /// <param name="company">工作公司</param>
    public void SetWorkExperience(string workDate, string company)
    {
        work.WorkDate = workDate;
        work.Company = company;
    }

    public void Display()
    {
        Console.WriteLine($"{name} {sex} {age}");
        Console.WriteLine($"工作经历：{work.WorkDate} {work.Company}");
    }


    public object Clone()
    {
        //在类内调用私有构造方法，让“工作经历”克隆完成，让后再给简历的相关字段赋值，最终返回一个深复制的简历对象。
        Resume obj = new Resume(this.work);
        obj.name = this.name;
        obj.sex = this.sex;
        obj.age = this.age;
        return obj;
    }
}
